#!/bin/sh

version=@VERSION@
build_type=@CMAKE_BUILD_TYPE_LOWER@
prefix=@CMAKE_INSTALL_PREFIX@
script_dir=@ZEEK_SCRIPT_INSTALL_PATH@
site_dir=@ZEEK_SCRIPT_INSTALL_PATH@/site
lib_dir=@CMAKE_INSTALL_FULL_LIBDIR@
plugin_dir=@BRO_PLUGIN_INSTALL_PATH@
config_dir=@ZEEK_ETC_INSTALL_DIR@
python_dir=@PY_MOD_INSTALL_DIR@
cmake_dir=@CMAKE_INSTALL_PREFIX@/share/zeek/cmake
include_dir=@CMAKE_INSTALL_PREFIX@/include
zeekpath=@DEFAULT_ZEEKPATH@
zeek_dist=@ZEEK_DIST@
binpac_root=@ZEEK_CONFIG_BINPAC_ROOT_DIR@
caf_root=@ZEEK_CONFIG_CAF_ROOT_DIR@
broker_root=@ZEEK_CONFIG_BROKER_ROOT_DIR@

add_path() {
    # $1: existing path
    # $2: path to add
    if test -z "$2" || test "$1" = "$2" ||
       echo "$1" | grep -q "^$2:" 2>/dev/null ||
       echo "$1" | grep -q ":$2:" 2>/dev/null ||
       echo "$1" | grep -q ":$2$" 2>/dev/null; then
        echo "$1"
        return
    fi

    echo "$1:$2"
}

include_dir=$(add_path "$include_dir" "@ZEEK_CONFIG_PCAP_INCLUDE_DIR@")
include_dir=$(add_path "$include_dir" "@ZEEK_CONFIG_ZLIB_INCLUDE_DIR@")
include_dir=$(add_path "$include_dir" "@ZEEK_CONFIG_OPENSSL_INCLUDE_DIR@")
include_dir=$(add_path "$include_dir" "@ZEEK_CONFIG_LibKrb5_INCLUDE_DIR@")
include_dir=$(add_path "$include_dir" "@ZEEK_CONFIG_GooglePerftools_INCLUDE_DIR@")

usage="\
Usage: zeek-config [--version] [--build_type] [--prefix] [--lib_dir] [--script_dir] [--site_dir] [--plugin_dir] [--config_dir] [--python_dir] [--include_dir] [--cmake_dir] [--zeekpath] [--zeek_dist] [--binpac_root] [--caf_root] [--broker_root]"

if [ $# -eq 0 ] ; then
      echo "${usage}" 1>&2
      exit 1
fi

while [ $# -ne 0 ]; do
  case "$1" in
  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  *) optarg= ;;
  esac

  case $1 in
    --binpac_root)
      echo $binpac_root
      ;;
    --bro_dist)  # For compatibility with legacy Bro plugins.
      echo $zeek_dist
      ;;
    --broker_root)
      echo $broker_root
      ;;
    --bropath)   # For compatibility with legacy Bro plugins.
      echo $zeekpath
      ;;
    --build_type)
      echo $build_type
      ;;
    --caf_root)
      echo $caf_root
      ;;
    --cmake_dir)
      echo $cmake_dir
      ;;
    --config_dir)
      echo $config_dir
      ;;
    --include_dir)
      echo $include_dir
      ;;
    --lib_dir)
      echo $lib_dir
      ;;
    --plugin_dir)
      echo $plugin_dir
      ;;
    --prefix)
      echo $prefix
      ;;
    --python_dir)
      echo $python_dir
      ;;
    --script_dir)
      echo $script_dir
      ;;
    --site_dir)
      echo $site_dir
      ;;
    --version)
      echo $version
      ;;
    --zeek_dist)
      echo $zeek_dist
      ;;
    --zeekpath)
      echo $zeekpath
      ;;
    *)
      echo "${usage}" 1>&2
      exit 1
      ;;
  esac
  shift
done

exit 0
